package com.jlnk.stockdemo.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.jlnk.stockdemo.R;
import com.jlnk.stockdemo.adapter.ViewPagerAdapter;

public class HotFragment extends Fragment {
    private static final String TAG = "HotFragment";

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hot, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        TabLayout tabLayout = view.findViewById(R.id.tabLayout);
        ViewPager viewPager = view.findViewById(R.id.viewPager);
        ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());
        adapter.addFragment(new StockFragment(), "股票");
        adapter.addFragment(new FuturesFragment(), "期货");
        adapter.addFragment(new SpotFragment(), "现货");
        adapter.addFragment(new BondsFragment(), "债券");
        adapter.addFragment(new ForexFragment(), "外汇");
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}
